package NC57_反转数字;

import java.util.*;


public class Solution {
    /**
     *
     * @param x int整型
     * @return int整型
     */
    public int reverse (int x) {
        // write code here
        int res = 0;
        while (x != 0){
            int last = x % 10;
            int newRes = res * 10 + last;

            // 如果数字溢出，直接返回 0
            if ((newRes - last) / 10 != res){
                return 0;
            }

            res = newRes;
            x = x / 10;
        }
        return res;
    }
}